<?php

namespace App\V3\V3_2_7\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\V3_2_7\VerifyIdRequest;
use App\V3\V3_2_7\Services\OutAnimalTagService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class OutAnimalTagController extends BaseController
{
    public function add(Request $request)
    {
        $data = $request->all();
        $time = time();
        $data['user_id'] = $this->getUserId();
        $data['main_id'] = $this->getMainUserId();
        $this->operateLog('创建宠物出库标签', $data, $time);
        return Cache::lock(__CLASS__ . __FUNCTION__ . $data['user_id'], 5)
            ->get(function () use ($data, $time) {
                return OutAnimalTagService::add($data, $time);
            });

    }

    public function update(VerifyIdRequest $request)
    {
        $data = $request->all();
        $time = time();
        $data['user_id'] = $this->getUserId();
        $data['main_id'] = $this->getMainUserId();
        $this->operateLog('修改宠物出库标签', $data, $time);
        return Cache::lock(__CLASS__ . __FUNCTION__ . $data['user_id'], 5)
            ->get(function () use ($data, $time) {
                return OutAnimalTagService::update($data, $time);
            });
    }

    public function del(VerifyIdRequest $request)
    {
        $data = $request->all();
        $time = time();
        $data['user_id'] = $this->getUserId();
        $data['main_id'] = $this->getMainUserId();
        $this->operateLog('删除宠物出库标签', $data, $time);
        return Cache::lock(__CLASS__ . __FUNCTION__ . $data['user_id'], 5)
            ->get(function () use ($data, $time) {
                return OutAnimalTagService::del($data, $time);
            });
    }

    public function list(Request $request)
    {
        $data = $request->all();
        $data['main_id'] = $this->getMainUserId();
        return $this->success(OutAnimalTagService::list($data));
    }
}
